﻿using SqlSugar;
using Dapper;
using ProductIntory.Infrastructures.Interface;
using Microsoft.EntityFrameworkCore;
using System.Threading.Tasks;

namespace ProductIntory.Infrastructures.Implement
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class, new()
    {
        private  DatabaseContextValue Dbcontext;
        private  DatabaseContext Sql;

        public BaseRepository(DatabaseContextValue Dbcontext, DatabaseContext Sql)
        {
            this.Dbcontext = Dbcontext;
            this.Sql = Sql;
        }

        public IQueryable<T> GetAll()
        {
            return Dbcontext.Set<T>();
        }

        public async Task<int> Add(T entity)
        {
            return await Sql.SqlSugar.Insertable(entity).ExecuteCommandAsync();
        }

        public async Task<int> Update(T entity)
        {
            return await Sql.SqlSugar.Updateable(entity).ExecuteCommandAsync();
        }
    }
}
